package logic

import (
	"context"
	"zhihu/models/mysql"

	"zhihu/zhihurpc/internal/svc"
	"zhihu/zhihurpc/zhihurpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ProblemaShowLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewProblemaShowLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ProblemaShowLogic {
	return &ProblemaShowLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ProblemaShowLogic) ProblemaShow(in *zhihurpc.ProblemaShowRequest) (*zhihurpc.ProblemaShowResponse, error) {
	// todo: add your logic here and delete this line
	var findProblma mysql.Problem
	mysql.DB.Debug().Where("id = ?", in.ProblmaId).Find(&findProblma)
	findProblma.Hot += 1

	mysql.DB.Debug().Updates(&findProblma)
	return &zhihurpc.ProblemaShowResponse{
		Title:        findProblma.Title,
		ProblemImage: findProblma.ProblemImage,
		Hot:          int64(findProblma.Hot),
		UserId:       int64(findProblma.UserId),
		ProblemId:    int64(findProblma.ID),
	}, nil
}
